<template>
    <div>
        动画片
        <el-alert type="success" >
            <template v-slot:title>
                <ul>
                    <li>1</li>
                    <li>1</li>
                    <li>1</li>
                </ul>
            </template>

            <template>
                <p>描述</p>
            </template>
        </el-alert>

        <el-alert 
            type="info"
            title="错误"
            description="描述"
            :closable="false"
            center
            showIcon
        ></el-alert>

        <hr/>

        <h1>封装表单并表单校验</h1>
        <!-- 用户名  密码 -->

        {{userInfo}}

        <bao-iForm :model="userInfo" :rules="rules" ref="form">
            <bao-form-item label="用户名" prop="username">
                <bao-iInput v-model="userInfo.username"></bao-iInput>
            </bao-form-item>
            <bao-form-item label="密码" prop="password">
                <bao-iInput v-model="userInfo.password"></bao-iInput>
            </bao-form-item>
            <button @click="submit">提交</button>
            <button @click="resetField">重置</button>
        </bao-iForm>
    </div>
</template> 

<script>
export default {
    data(){
        return {
            userInfo:{
                username:'',
                password:''
            },
            rules:{
                username:[
                    {required: true, message: '请输入用户名', trigger: 'blur'}
                ],
                password:[
                    {required: true, message: '请输入密码', trigger: 'blur'},
                    { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
                ]
            }
        }
    },
    methods:{
        //提交
        submit(){
            //
            this.$refs.form.validate((vaild) => {
                if(vaild){
                    console.log("通过校验")
                }else{
                    console.log("没有通过校验")
                }
            });
        },
        //重置表单
        resetField(){
            this.$refs.form.resetFields();
        }
    }
}
</script>
